package com.chuisha.stu.controller;

import com.chuisha.common.CommonResult;
import com.chuisha.stu.service.AccountFeign;
import com.chuisha.stu.service.OrderService;
import com.chuisha.stu.service.vo.AccountVO;
import com.chuisha.stu.service.vo.OrderVO;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@Log4j2
public class OrderController {
    @Autowired
    private AccountFeign accountFeign;
    @Autowired
    private OrderService orderService;

    @PostMapping("/order/getAccount/{accountCode}")
    public CommonResult<AccountVO> getAccount(@PathVariable String accountCode) {
        return accountFeign.getByCode(accountCode);
    }

    @GetMapping("/order/{orderNo}")
    public CommonResult<OrderVO> getByOrderNo(@PathVariable String orderNo) {
        log.info("get order detail,orderNo is :{}", orderNo);
        return CommonResult.success(orderService.selectByOrderNo(orderNo));
    }

    @PostMapping("/order/update")
    public CommonResult<OrderVO> update(OrderVO orderVO) {
        log.info("update order:{}", orderVO);
        return CommonResult.success(orderService.updateOrder(orderVO));
    }

    @PostMapping("/order/insert")
    public CommonResult<OrderVO> insert(OrderVO orderVO) {
        log.info("insert order:{}", orderVO);
        return CommonResult.success(orderService.insertOrder(orderVO));
    }

    @PostMapping("/order/delete")
    public CommonResult<Integer> delete(@RequestParam String orderCode) {
        log.info("delete order,orderCode is {}", orderCode);
        return CommonResult.success(orderService.deleteOrder(orderCode));
    }
}